package com.example.demo.level2;

import com.example.demo.level2.pojo.CustomFunction;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

public class GetUsedToFunctionInJava {

    private static final CustomFunction func1 = (a, b, c) -> {
        System.out.println("传进来了3个参数: " + a + " " + b + " " + c);
        System.out.println("a: " + a);
        System.out.println("b: " + b);
        System.out.println("c: " + c);
    };

    public static void main(String[] args) {
        func1.doSomeThing("1", 2, 3.0);
        // java.util.function 中有自带的函数式接口
        // java自带的生产者
        Supplier<Integer> supplier = () -> {
            System.out.println("进入 supplier");
            return 123;
        };
        // java自带的消费者
        Consumer<Integer> consumer = xx -> {
            System.out.println("进入 consumer");
            System.out.println(xx);
        };
        // java自带的函数
        Function<Integer, String> function = i -> {
            System.out.println("进入 function");
            return "转化成String: " + i.toString();
        };

        System.out.println("此时以上函数还没有开始执行");
        Integer x = supplier.get();
        consumer.accept(x);
        String str = function.apply(x);
        System.out.println(str);
    }
}
